//
//  QYRequestServer.m
//  QingYunZhi
//
//  Created by zhengminjie on 16/7/6.
//  Copyright © 2016年 zhengminjie. All rights reserved.
//

#import "MJRequestServer.h"
#import "AFNetworking.h"
#import <SVProgressHUD.h>

@implementation MJRequestServer


/*
 *通用POST
 */
+ (void)Post:(NSDictionary*)parameters success:(SDSenderBlock)success andFailure:(SDSenderBlock)failure{

    NSString *url = @"http://api.jisuapi.com/driverexam/query";
    
    AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
    [manager setResponseSerializer:[AFHTTPResponseSerializer serializer]];
    [manager POST:url parameters:parameters progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        if ([[dic objectForKey:@"status"] isEqualToString:@"0"]) {
            NSLog(@"msg ------ %@",dic);
            NSArray *arr = dic[@"result"][@"list"];
            success(arr);
        }else{
            NSLog(@"msg ------ %@",dic[@"msg"]);
        }

    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"errer------%@",error);
        failure(error);
    }];
    
}
/*
 *通用POST
 */
+ (void)Post:(NSDictionary*)parameters andApiName:(NSString *)apiname andAPI:(NSString *)API andSuccess:(SDSenderBlock)success andFailure:(SDSenderBlock)failure{
    
    NSString *requestPath1=[NSString stringWithFormat:@"%@",API];
    
    
    AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
    [manager setResponseSerializer:[AFHTTPResponseSerializer serializer]];
    [manager POST:requestPath1 parameters:parameters progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        NSLog(@"%@ -------%@",apiname,dic);
        success(dic);
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"errer------%@",error);
    }];
    
}
/*
 *通用get
 */
+ (void)Get:(NSDictionary*)parameters andApiName:(NSString *)apiname andAPI:(NSString *)API andSuccess:(SDSenderBlock)success andFailure:(SDSenderBlock)failure{
    
    NSString *requestPath1=[NSString stringWithFormat:@"%@",API];
    
    AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
    [manager setResponseSerializer:[AFHTTPResponseSerializer serializer]];
    [manager GET:requestPath1 parameters:parameters progress:^(NSProgress * _Nonnull downloadProgress) {
        //NSLog(@"totle --- %lld,current --- %lld",downloadProgress.totalUnitCount,downloadProgress.completedUnitCount);
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        //[responseObject mj_JSONObject];
        NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        NSLog(@"%@ -------%@",apiname,dic);

        success(dic);
            
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"errer------%@",error);
    }];
    
}







@end
